package pers.zyl.product.facade;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
public class FundFacade {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallback2")
    public String getFundMessage(Long userId, BigDecimal amount) {
        String url = "http://FUND/fund/account/balance/{userId}/{amount}";
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("amount", amount);
        return restTemplate.postForObject(url, null, String.class, params);
    }

    public String fallback2(Long userId, BigDecimal amount) {
        return "发生了错误";
    }

}
